package com.ccn.crm.interfaces.impl;

import com.ccn.crm.mapper.BeforeWorkingMapper;
import com.ccn.crm.model.AfterSales;
import com.ccn.crm.model.BeforeWorking;
import com.ccn.crm.service.IAfterSales;
import com.ccn.crm.util.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sun.rmi.runtime.Log;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class GetWorkTimeService implements IGetAfterSales {
    private static final Logger LOG = LoggerFactory.getLogger(GetWorkTimeService.class);
    @Autowired
    private IAfterSales iAfterSales;
    @Autowired
    private BeforeWorkingMapper beforeWorkingMapper;

    @Override
    public void getWorkTime() throws Exception {
        //获取crm系统token值
        Map<String, Object> token = GetToken.getToken();
        String corpAccessToken = (String) token.get("corpAccessToken");
        AfterSales afterSales = new AfterSales();
        //通过售后工单id插叙工单

        Map<String, Object> workTime = GetUsedWork.getWorkTime(token);
        String err = workTime.get("errorMessage").toString();
        System.out.println(err);
        if ("OK".equals(err)) {
            Map<String, Object> workTimeData = (Map<String, Object>) workTime.get("data");
            List<Map<String, Object>> workTimeDataList = (List<Map<String, Object>>) workTimeData.get("dataList");
            for (Map<String, Object> workTimeInfo : workTimeDataList) {
                System.out.println(workTimeInfo);
                if (null != workTimeInfo.get("field_tIlx0__c")) {
                    String workId = workTimeInfo.get("field_tIlx0__c").toString();
                    AfterSales workInfo = this.getWorkInfo(token, workId, afterSales);
                    if (null == workInfo) {
//                        System.out.println("没有查到售后单");
                        continue;
                    }
                    //工时所属日期
                    String creTime = workTimeInfo.get("field_Vqeky__c").toString();
//                    System.out.println("时间戳" + creTime);
                    Long aLong = Long.valueOf(creTime);

//                    Date aa = new Date(aLong);
                    Date creTim = new Date(aLong);
//                    System.out.println("后时间戳"+aLong+60000*60*12);
//                    System.out.println(creTim);
//                    System.out.println(workInfo.getWorkorder());
                    workInfo.setBelongdate(creTim);

                    String timeId = workTimeInfo.get("_id").toString();
//                    System.out.println(timeId);
                    workInfo.setTimeId(timeId);
                    AfterSales workOrd = iAfterSales.selectSalesByTimeId(timeId);
                    if (workOrd != null) {
//                        System.out.println(timeId);
                        continue;
                    } else {
                        LOG.info("获取售后工时的timeId：" + timeId);
                    }


                    //工时
                    if (null == workTimeInfo.get("field_YlY9n__c")) {
                        continue;
                    }
                    Double workingHours = Double.valueOf(workTimeInfo.get("field_YlY9n__c").toString());
                    workInfo.setWorkinghours(workingHours);
                    //创建人
                    List<Object> workCreateBy = (List<Object>) workTimeInfo.get("created_by");
                    Map<String, Object> workCreateByUser = GetUserInfo.GetUserInfo(workCreateBy, corpAccessToken);
                    String workCreateByUserName = (String) workCreateByUser.get("name");
                    workInfo.setWorkcreateby(workCreateByUserName);
                    //工时所属人timeBelongs

                    List<Object> timeBelongs = (List<Object>) workTimeInfo.get("field_nhnsa__c");

                    Map<String, Object> timeBelongsUser = GetUserInfo.GetUserInfo(timeBelongs, corpAccessToken);
                    if (timeBelongsUser.get("errorMessage").equals("success")) {
                        String timeBelongsUserName = (String) timeBelongsUser.get("name");
//                        System.out.println("查到的----"+timeBelongs);
                        workInfo.setTimebelongs(timeBelongsUserName);
                    } else {
                        //System.out.println("查询不到的id----"+timeBelongs);
                        LOG.info("查询不到的人员id" + timeBelongs);
                        continue;
                    }

                    workInfo.setDeleted("0");
                    int insert = iAfterSales.insert(workInfo);
                    if (insert > 0) {
                        LOG.info("售后工时添加成功");
                    } else {
                        LOG.info("售后工时添加失败");
                    }
                }
            }

        }

//        }
    }

    @Override
    public void updateWorkTime() throws Exception {
        //获取crm系统token值
        Map<String, Object> token = GetToken.getToken();
        List<AfterSales> afterSales = iAfterSales.selectAll();
        for (AfterSales afterSale : afterSales) {
            String timeId = afterSale.getTimeId();
            Map<String, Object> workTimeById = GetUsedWork.getWorkTimeById(token, timeId);
            String errorMessage = (String) workTimeById.get("errorMessage");
            System.out.println(errorMessage);
            if (errorMessage.equals("OK")) {
                Map<String, Object> workTimeData = (Map<String, Object>) workTimeById.get("data");
                List<Map<String, Object>> workTimeDataList = (List<Map<String, Object>>) workTimeData.get("dataList");
                String creTime = workTimeDataList.get(0).get("field_Vqeky__c").toString();
                System.out.println(creTime);
                String id = workTimeDataList.get(0).get("_id").toString();
                Long aLong = Long.valueOf(creTime);
                Date creTim = new Date(aLong);
                AfterSales afterSales1 = new AfterSales();
                afterSales1.setTimeId(id);
                afterSales1.setBelongdate(creTim);
                int i = iAfterSales.updateDateByTimeId(id, creTim);
                System.out.println(i);
                if (i > 0) {
                    System.out.println("修改时间成功");
                } else {
                    System.out.println("时间修改失败");
                    System.out.println(id);
                }
            }


        }

    }

    @Override
    public void getSqWorkTime() throws Exception {
        //获取crm系统token值
        Map<String, Object> token = GetToken.getToken();
        String corpAccessToken = (String) token.get("corpAccessToken");
        BeforeWorking beforeWorkings = new BeforeWorking();
        //通过售后工单id插叙工单

        Map<String, Object> workTime = GetUsedWork.getWorkTimeSq(token);
        String err = workTime.get("errorMessage").toString();
        System.out.println(err);
        if ("OK".equals(err)) {
            Map<String, Object> workTimeData = (Map<String, Object>) workTime.get("data");


            List<Map<String, Object>> workTimeDataList = (List<Map<String, Object>>) workTimeData.get("dataList");
            for (Map<String, Object> workTimeInfo : workTimeDataList) {

                if (null != workTimeInfo.get("field_S981V__c")) {
                    String workId = workTimeInfo.get("field_S981V__c").toString();
                    System.out.println(workTimeInfo);
                    BeforeWorking beforeWorking = this.getBeforeWorking(token, workId, beforeWorkings);
                    if (null==beforeWorking){
                        continue;
                    }
                    //流水号
                    if (null != workTimeInfo.get("name")) {
                        beforeWorking.setCode(workTimeInfo.get("name").toString());
                    }
                    //工时所属日期
                    String creTime = workTimeInfo.get("field_Vqeky__c").toString();
                    System.out.println("时间戳" + creTime);
                    Long aLong = Long.valueOf(creTime);

                    Date creTim = new Date(aLong);
//                    System.out.println("后时间戳"+aLong+60000*60*12);
//                    System.out.println(creTim);
//                    System.out.println(beforeWorking.getWorkorder());
                    beforeWorking.setBelongstime(creTim);

                    String timeId = workTimeInfo.get("_id").toString();
//                    System.out.println(timeId);
                    beforeWorking.setCrmid(timeId);
                    BeforeWorking beforeWork = beforeWorkingMapper.selectByCrmId(timeId);
                    if (beforeWork != null) {
//                        System.out.println(timeId);
                        continue;
                    } else {
                        LOG.info("获取售后工时的timeId：" + timeId);
                    }

                    if (null != workTimeInfo.get("field_09qHS__c")) {
                        List<Object> type = (List<Object>) workTimeInfo.get("field_09qHS__c");
                        String s = StringUtil.sqType(type);
                        beforeWorking.setType(s);
                    }
                    //工时
                    if (null == workTimeInfo.get("field_YlY9n__c")) {
                        continue;
                    }
                    Double workingHours = Double.valueOf(workTimeInfo.get("field_YlY9n__c").toString());
                    beforeWorking.setWorkinghours(workingHours.toString());

                    //工时所属人timeBelongs

                    List<Object> timeBelongs = (List<Object>) workTimeInfo.get("field_nhnsa__c");

                    Map<String, Object> timeBelongsUser = GetUserInfo.GetUserInfo(timeBelongs, corpAccessToken);
                    if (timeBelongsUser.get("errorMessage").equals("success")) {
                        String timeBelongsUserName = (String) timeBelongsUser.get("name");
//                        System.out.println("查到的----"+timeBelongs);
                        beforeWorking.setTimebelongs(timeBelongsUserName);
                    } else {
                        //System.out.println("查询不到的id----"+timeBelongs);
                        LOG.info("查询不到的人员id" + timeBelongs);
                        continue;
                    }

                    beforeWorking.setDeleted("0");
                    beforeWorking.setCreateddate(new Date(Long.valueOf(workTimeInfo.get("create_time").toString())));
                    int insert = beforeWorkingMapper.insert(beforeWorking);
                    if (insert > 0) {
                        LOG.info("售后工时添加成功");
                    } else {
                        LOG.info("售后工时添加失败");
                    }
                }
            }
        }

    }

    private AfterSales getWorkInfo(Map<String, Object> token, String id, AfterSales afterSales) throws Exception {
        Map<String, Object> afterSalesList = GetUsedWork.getAfterSales(token, id);
        String errorMessage = (String) afterSalesList.get("errorMessage");
        if ("OK".equals(errorMessage)) {
            Map<String, Object> data = (Map<String, Object>) afterSalesList.get("data");

            List<Map<String, Object>> dataList = (List<Map<String, Object>>) data.get("dataList");
            if (dataList.size() == 0) {
                return null;
            }
            for (Map<String, Object> afterSalesTime : dataList) {

                String workOrder = afterSalesTime.get("name").toString();

                afterSales.setWorkorder(workOrder);
//                System.out.println(afterSalesTime);
                Date workCreateTime = null;
                //问题发生时间
                if (null == afterSalesTime.get("field_26KVZ__c")) {

                } else {
                    workCreateTime = new Date(Long.valueOf(afterSalesTime.get("field_26KVZ__c").toString()) + 60000 * 60 * 13);
                }
                afterSales.setWorkcreatetime(workCreateTime);
//                    System.out.println("问题发生时间---"+workCreateTime);
                //是否客服处理
                String isOrNo = "--";
                if (null != afterSalesTime.get("field_8mlz7__c")) {
                    isOrNo = afterSalesTime.get("field_8mlz7__c").toString();
                    if (isOrNo.equals("option1")) {
                        isOrNo = "是";
                    } else {
                        isOrNo = "否";
                    }
                }
                afterSales.setIsorno(isOrNo);
                //状态
                String workOrderStatus = afterSalesTime.get("cases_status").toString();
                if (workOrderStatus.equals("X37K4bt71")) {
                    workOrderStatus = "未受理";
                } else if (workOrderStatus.equals("1")) {
                    workOrderStatus = "受理中";
                } else if (workOrderStatus.equals("2")) {
                    workOrderStatus = "技术处理中";
                } else if (workOrderStatus.equals("3")) {
                    workOrderStatus = "暂缓解决";
                } else if (workOrderStatus.equals("T5uC7fq7G")) {
                    workOrderStatus = "验证与回访";
                } else if (workOrderStatus.equals("4")) {
                    workOrderStatus = "已关闭";
                } else if (workOrderStatus.equals("cxAvEow19")) {
                    workOrderStatus = "事件监控中";
                } else {
                    workOrderStatus = "新类型请去代码添加";
                }
                afterSales.setWorkorderstatus(workOrderStatus);
                String corpAccessToken = (String) token.get("corpAccessToken");
                //负责人
                List<Object> owner = (List<Object>) afterSalesTime.get("owner");
                Map<String, Object> user = GetUserInfo.GetUserInfo(owner, corpAccessToken);
                String userName = (String) user.get("name");
                afterSales.setHead(userName);
                //事件服务等级
                if (null == afterSalesTime.get("field_2ePd6__c")) {
                    afterSales.setEventlevel("--");
                } else {
                    String eventLevel = afterSalesTime.get("field_2ePd6__c").toString();
                    if (eventLevel.equals("option1")) {
                        eventLevel = "一级（通用）";
                    } else if (eventLevel.equals("hf3ML2019")) {
                        eventLevel = "二级（通用）";
                    } else if (eventLevel.equals("4r5gm9A35")) {
                        eventLevel = "三级（通用）";
                    } else if (eventLevel.equals("r99n1xPR7")) {
                        eventLevel = "壳牌售后服务等级";
                    } else if (eventLevel.equals("wd83Xe041")) {
                        eventLevel = "美赞臣售后服务等级";
                    } else if (eventLevel.equals("bw1So94Om")) {
                        eventLevel = "合生元售后服务等级";
                    } else if (eventLevel.equals("2271L8P0m")) {
                        eventLevel = "汤成倍健售后服务等级";
                    } else if (eventLevel.equals("other")) {
                        eventLevel = "新类型请去代码添加";
                    }
                    afterSales.setEventlevel(eventLevel);
                }
                //是否重大投诉
                if (null == afterSalesTime.get("field_0991c__c")) {
                    afterSales.setComplaints("--");
                } else {
                    String complaints = afterSalesTime.get("field_0991c__c").toString();
                    if (complaints.equals("option1")) {
                        complaints = "是";
                    } else if (complaints.equals("g5Um5a2Bn")) {
                        complaints = "否";
                    } else if (complaints.equals("other")) {
                        complaints = "其他";
                    } else {
                        complaints = "新类型请去代码添加";

                    }
                    afterSales.setComplaints(complaints);
                }
                //是否赔偿
                if (null == afterSalesTime.get("field_fK72L__c")) {
                    afterSales.setCompensation("--");
                } else {
                    String compensation = afterSalesTime.get("field_fK72L__c").toString();
                    if (compensation.equals("option1")) {
                        compensation = "是";
                    } else if (compensation.equals("5r1Unuq7u")) {
                        compensation = "否";
                    } else if (compensation.equals("other")) {
                        compensation = "其他";
                    } else {
                        compensation = "新类型请去代码添加";
                    }
                    afterSales.setCompensation(compensation);
                }
                //  事件大类
                if (null == afterSalesTime.get("field_sl85q__c")) {
                    afterSales.setEventbigclass("--");
                } else {
                    String eventBigClass = afterSalesTime.get("field_sl85q__c").toString();
                    if (eventBigClass.equals("fO6yJkIg1")) {
                        eventBigClass = "标签产品";
                    } else if (eventBigClass.equals("99LJ7ucqu")) {
                        eventBigClass = "硬件售后";
                    } else if (eventBigClass.equals("9rgje6x11")) {
                        eventBigClass = "产线软件";
                    } else if (eventBigClass.equals("681FvCL76")) {
                        eventBigClass = "数字营销产品";
                    } else if (eventBigClass.equals("C1GocPouo")) {
                        eventBigClass = "追溯产品";
                    } else if (eventBigClass.equals("nRn9vs2TT")) {
                        eventBigClass = "内部系统";
                    } else if (eventBigClass.equals("31zoT80Rp")) {
                        eventBigClass = "新需求";
                    } else if (eventBigClass.equals("other")) {
                        eventBigClass = "其他";
                    } else {
                        eventBigClass = "新类型请去代码添加";
                    }

                    afterSales.setEventbigclass(eventBigClass);
                }
                //  事件zi类
                if (null == afterSalesTime.get("field_f87Cc__c")) {
                    afterSales.setEventsmallclass("--");
                } else {
                    String eventSmallClass = afterSalesTime.get("field_f87Cc__c").toString();
                    if (eventSmallClass.equals("4qDXWr8Kz")) {
                        eventSmallClass = "印刷问题";
                    } else if (eventSmallClass.equals("g0x6u1n47")) {
                        eventSmallClass = "物流问题";
                    } else if (eventSmallClass.equals("k1hyjRyPJ")) {
                        eventSmallClass = "包装问题";
                    } else if (eventSmallClass.equals("9dO84Nx1o")) {
                        eventSmallClass = "扫描设备";
                    } else if (eventSmallClass.equals("32lMJxms8")) {
                        eventSmallClass = "生产线问题";
                    } else if (eventSmallClass.equals("i1k66hlgx")) {
                        eventSmallClass = "总控机";
                    } else if (eventSmallClass.equals("3m08u545R")) {
                        eventSmallClass = "分控机";
                    } else if (eventSmallClass.equals("xALWfwM04")) {
                        eventSmallClass = "配件";
                    } else if (eventSmallClass.equals("26uGe8p3g")) {
                        eventSmallClass = "活动终端";
                    } else if (eventSmallClass.equals("9C3nt6zeG")) {
                        eventSmallClass = "客户端追溯系统";
                    } else if (eventSmallClass.equals("0l1xjPzSb")) {
                        eventSmallClass = "大黄蜂追溯系统";
                    } else if (eventSmallClass.equals("d7SbmhNl0")) {
                        eventSmallClass = "通用追溯系统";
                    } else if (eventSmallClass.equals("i5kdq4dm4")) {
                        eventSmallClass = "报表平台问题";
                    } else if (eventSmallClass.equals("izp9e13x1")) {
                        eventSmallClass = "客服应用工具";
                    } else if (eventSmallClass.equals("v31r1oUFe")) {
                        eventSmallClass = "系统运维问题";
                    } else if (eventSmallClass.equals("OEt6B97Wf")) {
                        eventSmallClass = "新需求";
                    } else if (eventSmallClass.equals("d5gsgqm0S")) {
                        eventSmallClass = "防伪查询系统";
                    } else if (eventSmallClass.equals("c5gzLXV2R")) {
                        eventSmallClass = "“智慧树”追溯产品";
                    } else if (eventSmallClass.equals("TkSjU0wGt")) {
                        eventSmallClass = "超8系统";
                    } else if (eventSmallClass.equals("ExCTL2E72")) {
                        eventSmallClass = "项目类支持";
                    } else if (eventSmallClass.equals("other")) {
                        eventSmallClass = "活动后台系统";
                    } else {
                        eventSmallClass = "新类型请去代码添加";
                    }
                    afterSales.setEventsmallclass(eventSmallClass);
                }
                //责任类型 ResponType
                if (null == afterSalesTime.get("field_4c2xM__c")) {
                    afterSales.setRespontype("--");
                } else {
                    List<String> responType = (List<String>) afterSalesTime.get("field_4c2xM__c");
                    String be = "";
                    String tex = "";

                    for (int i = 0; i < responType.size(); i++) {
                        if (responType.get(i).equals("option1")) {
                            tex = "CCN";
                        } else if (responType.get(i).equals("nL22S8V3z")) {
                            tex = "客户";
                        } else if (responType.get(i).equals("ze25K8Suf")) {
                            tex = "未知";
                        } else if (responType.get(i).equals("WAG6127lG")) {
                            tex = "CCN供应商";
                        } else if (responType.get(i).equals("other")) {
                            tex = "其他";
                        } else {
                            tex = "类型不存在请去添加";
                        }
                        be = be + tex + "/";
                        be = be.substring(0, be.length() - 1);
                    }
                    afterSales.setRespontype(be);
                }
                //责任部门
                if (null == afterSalesTime.get("field_r2kz4__c")) {
                    afterSales.setRespondept("--");
                } else {
                    List<Object> responDept = (List<Object>) afterSalesTime.get("field_r2kz4__c");
                    if (!responDept.isEmpty()) {
                        Map<String, Object> stringObjectMap = GetDeptInfo.GetDeptInfoBycode(responDept, corpAccessToken);
                        String errorMessages = (String) afterSalesList.get("errorMessage");
                        if ("OK".equals(errorMessages)) {
                            if (null == stringObjectMap.get("department")) {
                                afterSales.setRespondept("--");
                            } else {
                                Map<String, Object> department = (Map<String, Object>) stringObjectMap.get("department");
                                String deptName = department.get("name").toString();
                                afterSales.setRespondept(deptName);
                            }
                        } else {
                            afterSales.setRespondept("--");
                        }
                    } else {
                        afterSales.setRespondept("--");
                    }
                }

                //责任人员
                if (null == afterSalesTime.get("field_mp1Qu__c")) {
                    afterSales.setResponuser("--");
                } else {
                    List<Object> responUser = (List<Object>) afterSalesTime.get("field_mp1Qu__c");
                    if (!responUser.isEmpty()) {
                        String errorMessagess = (String) afterSalesList.get("errorMessage");
                        if ("OK".equals(errorMessagess)) {
                            Map<String, Object> responUsers = GetUserInfo.GetUserInfo(responUser, corpAccessToken);
                            if (null == responUsers.get("name")) {
                                afterSales.setResponuser("--");
                            } else {
                                String responUserName = (String) responUsers.get("name");
                                afterSales.setResponuser(responUserName);
                            }
                        }
                    } else {
                        afterSales.setResponuser("--");
                    }
                }

                //客服描述
                String employDescribe = "";
                if (null == afterSalesTime.get("field_w5WCC__c")) {
                    employDescribe = "--";
                } else {
                    employDescribe = afterSalesTime.get("field_w5WCC__c").toString();
                }
                afterSales.setEmploydescribe(employDescribe);
                //原因分析
                if (null == afterSalesTime.get("field_74Oak__c")) {
                    afterSales.setAnalysis("--");
                } else {
                    String analysis = afterSalesTime.get("field_74Oak__c").toString();
                    afterSales.setAnalysis(analysis);
                }
                //解决方案
                if (null == afterSalesTime.get("field_OYbuc__c")) {
                    afterSales.setSolution("--");
                } else {
                    String solution = afterSalesTime.get("field_OYbuc__c").toString();
                    afterSales.setSolution(solution);
                }
                //原因类别
                if (null == afterSalesTime.get("field_9QK3W__c")) {
                    afterSales.setReasoncategory("--");
                } else {
                    List<Object> reasonCategory = (List<Object>) afterSalesTime.get("field_9QK3W__c");
                    String bec = "";
                    String text = "";
                    if (!reasonCategory.isEmpty()) {

                        for (int i = 0; i < reasonCategory.size(); i++) {
                            if (reasonCategory.get(i).equals("g601Y2Tl4")) {
                                text = "模切";
                            } else if (reasonCategory.get(i).equals("g601Y2Tl4")) {
                                text = "套印";
                            } else if (reasonCategory.get(i).equals("m45xmyA7z")) {
                                text = "色差";
                            } else if (reasonCategory.get(i).equals("Hf75SonY5")) {
                                text = "胶水";
                            } else if (reasonCategory.get(i).equals("u5FyTbUyx")) {
                                text = "硬件故障";
                            } else if (reasonCategory.get(i).equals("pvnHFga24")) {
                                text = "配置问题";
                            } else if (reasonCategory.get(i).equals("ITK1wjgmw")) {
                                text = "系统bug";
                            } else if (reasonCategory.get(i).equals("7at5nNwc9")) {
                                text = "兼容性问题";
                            } else if (reasonCategory.get(i).equals("8BAzOxWc5")) {
                                text = "人员疏忽（误操作）";
                            } else if (reasonCategory.get(i).equals("8GCih1nXx")) {
                                text = "服务器异常";
                            } else if (reasonCategory.get(i).equals("8ob38d6kp")) {
                                text = "数据库的问题";
                            } else if (reasonCategory.get(i).equals("gB57C71aD")) {
                                text = "系统安装/培训";
                            } else if (reasonCategory.get(i).equals("Vz420Wm1")) {
                                text = "运行环境问题";
                            } else if (reasonCategory.get(i).equals("otUc1t134")) {
                                text = "未知问题";
                            } else if (reasonCategory.get(i).equals("17winVUdD")) {
                                text = "咨询需求";
                            } else if (reasonCategory.get(i).equals("2D53Xban0")) {
                                text = "系统优化";
                            } else if (reasonCategory.get(i).equals("other")) {
                                text = "其他";
                            } else {
                                text = "未知字段去添加";
                            }
                            bec = bec + text + "/";
                            bec = bec.substring(0, bec.length() - 1);
                        }
                    } else {
                        afterSales.setReasoncategory("--");
                    }
                    afterSales.setReasoncategory(bec);
                }
                //原因大类
                if (null == afterSalesTime.get("field_F9N5z__c")) {
                    afterSales.setReasonbigclass("--");
                } else {
                    List<String> reasonBigClass = (List<String>) afterSalesTime.get("field_F9N5z__c");
                    String bigClass = "";
                    String rea = "";
                    for (int j = 0; j < reasonBigClass.size(); j++) {
                        if (reasonBigClass.get(j).equals("85iWu6R75")) {
                            rea = "人员疏忽（人）";
                        } else if (reasonBigClass.get(j).equals("fD783v5Ax")) {
                            rea = "设备硬件问题（机）";
                        } else if (reasonBigClass.get(j).equals("0ybJZb4a0")) {
                            rea = "材料问题（物）";
                        } else if (reasonBigClass.get(j).equals("w2C51495I")) {
                            rea = "流程及规定（法）";
                        } else if (reasonBigClass.get(j).equals("o2R2Bn15e")) {
                            rea = "环境问题（环）";
                        } else if (reasonBigClass.get(j).equals("Hz2DfO006")) {
                            rea = "咨询/需求";
                        } else if (reasonBigClass.get(j).equals("LC0a4G2wv")) {
                            rea = "其他未知";
                        } else if (reasonBigClass.get(j).equals("other")) {
                            rea = "其他";
                        } else {
                            rea = "未知字段请去代码添加";
                        }
                        bigClass = bigClass + rea + "/";
                        bigClass = bigClass.substring(0, bigClass.length() - 1);
                    }
                    afterSales.setReasonbigclass(bigClass);
                }
                //开始处理时间 field_jEZK3__c
                if (null == afterSalesTime.get("field_jEZK3__c")) {
                    afterSales.setStardealtime(null);
                } else {
                    Date starDealTime = new Date(Long.valueOf(afterSalesTime.get("field_jEZK3__c").toString()) + 60000 * 60 * 13);
                    afterSales.setStardealtime(starDealTime);
                }

                //配置客户名称
                String customerName = afterSalesTime.get("account_id__r").toString();
                afterSales.setCustomername(customerName);
                //售后工单工时id
//                String workId = afterSalesTime.get("_id").toString();
//                System.out.println(workId);


            }

        }
        return afterSales;

    }

    private BeforeWorking getBeforeWorking(Map<String, Object> token, String id, BeforeWorking beforeWorking) throws Exception {
        Map<String, Object> afterSalesSqMap = GetUsedWork.getSqWorkTimeById(token, id);
        String errorMessage = (String) afterSalesSqMap.get("errorMessage");
        if ("OK".equals(errorMessage)) {
            Map<String, Object> data = (Map<String, Object>) afterSalesSqMap.get("data");

            List<Map<String, Object>> dataList = (List<Map<String, Object>>) data.get("dataList");
            if (dataList.size() == 0) {
                return null;
            }
            for (Map<String, Object> afterSalesSq : dataList) {

                if (null != afterSalesSq.get("field_8hWBz__c")) {
                    beforeWorking.setOppocode(afterSalesSq.get("field_8hWBz__c").toString());
                }
                //商机名字
                if (null != afterSalesSq.get("field_GJcl1__c")) {
                    Map<String, Object> oppo = GetUsedWork.getOppoInfo(token, afterSalesSq.get("field_GJcl1__c").toString());
                    if (oppo.isEmpty()) {
                        beforeWorking.setOpponame("");
                    } else {
                        Map<String, Object> oppoinfo = (Map<String, Object>) oppo.get("data");
                        if (null != oppoinfo.get("name")) {
                            beforeWorking.setOpponame(oppoinfo.get("name").toString());
                        } else {
                            beforeWorking.setOpponame("");
                        }
                    }

                }else {
                    beforeWorking.setOpponame("");
                }

                if (null != afterSalesSq.get("field_HwTmJ__c")) {
                    //客户名称
                    Map<String, Object> stringObjectMap = GetCustomerInfo.GetCustomerInfo(afterSalesSq.get("field_HwTmJ__c").toString(), token);

                    if (stringObjectMap.isEmpty()) {
                        beforeWorking.setCustomername("");
                    } else {
                        Map<String, Object> customerInfo = (Map<String, Object>) stringObjectMap.get("data");
                        if (null != customerInfo.get("name")) {
                            beforeWorking.setCustomername(customerInfo.get("name").toString());
                        } else {
                            beforeWorking.setCustomername("");
                        }
                    }
                }else {
                    beforeWorking.setCustomername("");
                }
            }
        }
        return beforeWorking;
    }
}